{template 'common/header-storex'}
<div class="wn-main">
	<div class="wn-main__head">
		{if !empty($_GPC['title'])}
		<a href="{php echo $this->createWebUrl('shop_comment',array('storeid'=>$storeid))}">商品评价</a> / {$_GPC['title']}
		{else}
			商品评价
		{/if}
	</div>
	<div class="wn-main__content">
		<div class="wn-main__search clearfix">
			<div class="wn-main__search__form" style="width: 600px">
				<form action="./index.php" method="get" class="form-horizontal from" role="form">
					<input type="hidden" name="c" value="site" />
					<input type="hidden" name="a" value="entry" />
					<input type="hidden" name="m" value="wn_storex" />
					<input type="hidden" name="do" value="shop_comment" />
					<input type="hidden" name="storeid" value="{$storeid}">
					<div class="form-group">
						<div class="col-xs-12 col-sm-8 col-lg-9">
							<div class="input-group">
								<input class="form-control" name="title" placeholder="请输入商品名称" id="" type="text" value="{$_GPC['title']}">
								<span class="input-group-btn">
									<button class="btn btn-default"><i class="fa fa-search"></i></button>
								</span>
							</div>
						</div>
					</div>
				</form>
			</div>
			<div class="wn-main__search__action">
				<a href="{php echo $this->createWebUrl('shop_comment', array('op' => 'post', 'storeid' => $storeid));}" class="btn btn-primary we7-padding-horizontal">+添加虚拟评价</a>
			</div>
		</div>
		<table class="table table-hover table-bordered wn-table" >
			<thead class="navbar-inner">
			<tr>
				<th class='with-checkbox' style='width:30px;'>
					<input type="checkbox" class="check_all" />
				</th>
				<th style="width:120px;">商品名称</th>
				<th style="width:300px;">评论内容</th>
				<th style='width:100px;'>评价级别</th>
				<th style="width:150px;">评论时间</th>
				<th style='width:120px;'>评论者</th>
				<th style="width:320px;">操作</th>
			</tr>
			</thead>
			<tbody>
			{loop $comments $item}
			<tr>
				<td class="with-checkbox">
					<input type="checkbox" name="check" value="{$item['id']}">
				</td>
				<td>{$item['title']}</td>
				<td>{$item['comment']}</td>
				<td>{$item['comment_level']}</td>
				<td>{$item['createtime']}</td>
				<td>
					<img src="{php echo tomedia($item['thumb'])}" width="33px">
					{$item['nickname']}
				</td>
				<td>
					<div class="wn-table__link">
						<a class="wn-table__link__item js-reply-comment" href="javascript:;" data-id="{$item['id']}" data-goodsid="{$item['goodsid']}">回复</a>
						<a class="wn-table__link__item" href="{php echo $this->createWebUrl('shop_comment',array('op' => 'post', 'id' => $item['id'], 'storeid' => $storeid))}" title="编辑">编辑</a>
						<a class="wn-table__link__item" href="#" onclick="drop_confirm('您确定要删除该评论吗?', '{php echo $this->createWebUrl('shop_comment',array('op' => 'delete', 'cid' => $item['id'], 'storeid' => $storeid, 'id' => $item['goodsid']))}');" title="删除">删除</a>
					</div>

				</td>
			</tr>
			{loop $item['reply'] $reply}
			<tr>
				<td colspan="2" class="text-center">商家回复</td>
				<td colspan="2">{$reply['comment']}</td>
				<td>{$reply['createtime']}</td>
				<td>{$reply['nickname']}</td>
				<td>
					<a class="wn-table__link__item" href="#" onclick="drop_confirm('您确定要删除该评论吗?', '{php echo $this->createWebUrl('shop_comment',array('op' => 'delete', 'cid' => $reply['id'], 'storeid' => $storeid, 'id' => $reply['goodsid']))}');" title="删除">删除</a
				</td>
			</tr>
			{/loop}
			{/loop}
			<tr>
				<td></td>
				<td colspan="6">
					<input type="button" class="btn btn-primary" data-toggle="tooltip" data-placement="bottom"  title="删除选择的" name="deleteall" value="删除选择的" />
					<div class="pull-right">
						{$pager}
					</div>
				</td>
			</tr>
			</tbody>
		</table>
	</div>
</div>
<div class="modal fade" id="reply-modal" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">回复评论</h4>
			</div>
			<div class="modal-body clearfix form-horizontal">
				<input type="text" class="form-control" name="reply" />
				<input type="hidden" name="cid">
				<input type="hidden" name="goodsid">
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-primary js-reply-submit">确定</button>
			</div>
		</div>
	</div>
</div>
<script>
	$(function() {
		$('.js-reply-comment').click(function() {
			cid = $(this).data('id');
			goodsid = $(this).data('goodsid');
			$('input[name="cid"]').val(cid);
			$('input[name="goodsid"]').val(goodsid);
			$('#reply-modal').modal('show');
		});
		$('.js-reply-submit').click(function() {
			cid = $('input[name="cid"]').val();
			goodsid = $('input[name="goodsid"]').val();
			reply = $('input[name="reply"]').val();
			if (!reply) {
				util.message('回复内容不能为空');
			}
			$.post("{php echo $this->createWebUrl('shop_comment', array('op' => 'reply', 'storeid' => $_GPC['storeid']))}", {cid : cid, comment : reply, goodsid : goodsid}, function(data) {
				data = $.parseJSON(data);
				if (data.message.errno != 0) {
					util.message(data.message.message, '', 'error');
				} else {
					util.message('回复成功', location.href, 'success');
				}
				$('#reply-modal').modal('hide');
			});
		});
		$(".check_all").click(function() {
			var checked = $(this).get(0).checked;
			$("input[type=checkbox]").prop("checked",checked);
		});
		$("input[name=deleteall]").click(function() {
			var check = $("input[name='check']:checked");
			if (check.length < 1) {
				alert('请选择要删除的记录!');
				return false;
			}
			if (confirm("确认要删除选择的记录?")) {
				var id = new Array();
				check.each(function(i){
					id[i] = $(this).val();
				});
				$.post("{php echo $this->createWebUrl('shop_comment',array('op'=>'deleteall', 'store_base_id' => $store_base_id, 'id' => $id, 'store_type' => $store_type))}", {idArr:id},function(data){
					if (data.message.errno ==0) {
						util.message(data.message.message, 'refresh', 'success');
					} else {
						util.message(data.message.message);
					}
				},'json');
			}
		});
	});
	function drop_confirm(msg, url) {
		if (confirm(msg)) {
			window.location = url;
		}
	}
</script>
{template 'common/footer-storex'}